﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using Business.FlowOperation;

public partial class MyWindow_CreateWorkFlow : PageBase
{
    public RequestFlowOperation flowOperation = new RequestFlowOperation();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvList_OnLoadData(object sender, EventArgs e)
    {
        BindData();
    }

    /// <summary>
    /// 数据绑定
    /// </summary>
    public void BindData()
    {
        var dtTemp = flowOperation.GetWorkFlowByUserId(UserId);
        gvList.DataSource = dtTemp;
        gvList.RecordCount = dtTemp.Rows.Count;
        gvList.DataBind();
    }

    protected void linkBtnApply_Click(object sender, EventArgs e)
    {
        var wid = (sender as LinkButton).CommandArgument;
        string strWiid = string.Empty;
        string strErrorMsg = string.Empty;
        int nResult = flowOperation.BuildTask(wid, UserId, UserName, ref strWiid, ref strErrorMsg);
        if (nResult == 1)
        {
            Response.Redirect("TaskInStepList.aspx?wiid=" + strWiid + "&isopen=true");
        }
        else//创建流程失败
        {
            string strScript = string.Format("<script>alert(\"创建流程失败：{0}\")</script>", strErrorMsg);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", strScript);
        }
    }
}